<template>
    <split-horizontal>
        <template v-slot:header-p>
            <div class="j-title">
                视频暂停广告组件（JVideoAdvertisement）
                <div class="j-detail">
                    视频暂停播放的时候会播放广告，支持版本^0.9.0
                </div>
            </div>
        </template>
        <template v-slot:mid-p>
            <div class="content">
                <div class="video-list">
                    <JVideoAdvertisement
                        class="video"
                        :videoUrl="videoUrl"
                        :height="videoHeight"
                        :width="videoWidth"
                        :advertisementUrl="advertisementUrl"
                        :advertisementImg="advertisementImg"
                    >
                    </JVideoAdvertisement>
                </div>
            </div>
            <div>
                <j-table :title="tableTitle" :tableData="tableData"> </j-table>
            </div>
        </template>
        <template v-slot:footer-p>
            <pre v-highlight>
                <code class="vue">
                    <div v-text="code"></div>
                </code>
            </pre>
        </template>
    </split-horizontal>
</template>
<script>
import { mixinForView } from "@/mixins/index.js";
export default {
    name: "JVideoAdvertisementView",
    components: {},
    mixins: [mixinForView],
    data() {
        return {
            code: "",
            videoUrl: require("../../assets/video/密码箱.mp4"),
            advertisementUrl: require("../../assets/video/20241211010054-video.mp4"),
            advertisementImg: require("../../assets/img/1701306017767.jpg"),
            tableData: [],
            videoWidth: "768px",
            videoHeight: "412px",
        };
    },
    created() {
        this.initVideoBox();
        this.initTableData();
        this.initCodeContent();
    },
    mounted() {},
    methods: {
        initVideoBox() {
            const videoWidth = parseInt(this.videoWidth);
            const videoHeight = parseInt(this.videoHeight);
            const rate = videoWidth / videoHeight;
            const width = window.innerWidth;
            const height = window.innerHeight;
            if (width < height) {
                this.videoWidth = width * 0.95 + "px";
                this.videoHeight = (width * 0.95) / rate + "px";
            }
        },
        initCodeContent() {
            this.code = `
<template>
    <div class="content">
        <div class="video-list">
            <JVideoAdvertisement
                class="video"
                :videoUrl="videoUrl"
                :height="videoHeight"
                :width="videoWidth"
                :advertisementUrl="advertisementUrl"
                :advertisementImg="advertisementImg"
            >
            </JVideoAdvertisement>
        </div>
    </div>
</template>

export default {
    data() {
        return {
            videoUrl: require("../../assets/video/密码箱.mp4"),
            advertisementUrl: require("../../assets/video/20241211010054-video.mp4"),
            advertisementImg: require("../../assets/img/1701306017767.jpg"),
            videoWidth: "768px",
            videoHeight: "412px",
        }
    },
    created() {
        this.initVideoBox();
    },
    methods:{
        initVideoBox() {
            const videoWidth = parseInt(this.videoWidth);
            const videoHeight = parseInt(this.videoHeight);
            const rate = videoWidth / videoHeight;
            const width = window.innerWidth;
            const height = window.innerHeight;
            if (width < height) {
                this.videoWidth = width * 0.95 + "px";
                this.videoHeight = (width * 0.95) / rate + "px";
            }
        },
    }
}
        `;
        },
        initTableData() {
            this.tableData = [
                {
                    parameter: "width",
                    field: "视频宽度",
                    type: "String",
                    describe: "默认值为300px",
                },
                {
                    parameter: "height",
                    field: "视频高度",
                    type: "String",
                    describe: "默认值为200px",
                },
                {
                    parameter: "videoUrl",
                    field: "视频链接",
                    type: "String",
                    describe: "视频链接地址，本地视频需要使用require",
                },
                {
                    parameter: "advertisementUrl",
                    field: "广告视频链接",
                    type: "String",
                    describe: "视频暂停后播放",
                },
                {
                    parameter: "advertisementImg",
                    field: "广告图片链接",
                    type: "String",
                    describe: "视频暂停后显示",
                },
                {
                    parameter: "loop",
                    field: "循环播放",
                    type: "Boolean",
                    describe: "视频是否循环播放，默认为false",
                },
            ];
        },
    },
};
</script>
<style scoped lang="less">
.title {
    font-size: x-large;
    text-align: left;
    margin-bottom: 1rem;
    .detail {
        font-size: medium;
        color: dimgrey;
        margin-top: 1rem;
    }
}
.content {
    margin: auto auto;
    .video-list {
        display: flex;
        flex-wrap: wrap;
        .video {
            margin: auto;
        }
    }
}
.header {
    min-height: 4rem;
    text-align: center;
}
.footer {
    margin-top: 2rem;
    margin-left: 2%;
    width: 95%;
}
</style>
